﻿
#region Usings

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

#endregion

namespace FasterWPF
{
    public class CanvasArgs
    {
        public double? Left { get; set; }
        public double? Top { get; set; }
        public int? ZIndex { get; set; }

        public CanvasArgs(double? left, double? top, int? zIndex)
        {
            Left = left;
            Top = top;
            ZIndex = zIndex;        
        }
    }

    public class CanvasParent : FasterWPF.IParent 
    {         
        //this is ANA?
        public object Generate<T>(object chain, T args, Action<ContentControl> addUIElementsAction)
        {
            return chain;
        }

        //this is BIND
        public object Add<T>(object chain, string key, T args, Border itemToAdd)
        {
            if (args is CanvasArgs)
            {
                if ((args as CanvasArgs).Left != null)
                {
                    Canvas.SetLeft(itemToAdd, (double)(args as CanvasArgs).Left);
                }

                if ((args as CanvasArgs).Top != null)
                {
                    Canvas.SetTop(itemToAdd, (double)(args as CanvasArgs).Top);
                }

                if ((args as CanvasArgs).ZIndex != null)
                {
                    Canvas.SetZIndex(itemToAdd, (int)(args as CanvasArgs).ZIndex);
                }
            }

            ((Canvas)chain).Children.Add(itemToAdd);
            return chain;
        }

        public void Remove(object chain, string key, Border itemToRemove)
        {
            ((Canvas)chain).Children.Remove(itemToRemove); //remove from Window

            IComposite ic = (IComposite)(((Canvas)chain).GetIComposite<Canvas>());
            ic.RemoveFromChain(itemToRemove);
        }

        public Dictionary<string, object> RetrieveDictionary(object chain)
        {
            return ((Canvas)chain).GetCompositeLookupDictionary<Canvas>();
        }

        //this is CATA?
        public List<Border> RetrieveCollection(object chain)
        {
            List<Border> lb = new List<Border>();
            foreach (var kvp in ((Canvas)chain).GetCompositeLookupDictionary<Canvas>())
            {
                lb.Add((Border)kvp.Value);
            }

            return lb;
        }

        public void ClearCollection(object chain)
        {
        }

        public void BeforeSortCollection<T>(object chain, object args, int row, int column, FasterWPF.CommonExt.SortOrder sortOrder)
                  where T : FrameworkElement
        { }

        public void BeforeSortCollection1Then2<T>(object chain, object args, int row, int column, int row2, int column2, FasterWPF.CommonExt.SortOrder sortOrder, FasterWPF.CommonExt.SortOrder sortOrder2)
  where T : FrameworkElement
        { }
        
        public void AfterSortCollection<T>(object chain)
             where T : FrameworkElement
        { }

        public void InnerSortCollection(object chain, int row, int column, string key, ref int counter, Border itemToReAdd)
        {
            throw new NotImplementedException();
        }
        
        public void SetSelected(object chain, Border itemToSetAsSelected)
        {
        }

        //public void GetSelected
        //    return (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem);

    }
}
